#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include <afxdllx.h>

HINSTANCE _hdllInstance =NULL ;

void AddCommand(const TCHAR* cmdGroup, const TCHAR* cmdInt, const TCHAR* cmdLoc,
				const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);


void InitApplication();
void UnloadApplication();

AC_IMPLEMENT_EXTENSION_MODULE(TtArxDLL);

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		_hdllInstance = hInstance;
		TtArxDLL.AttachInstance(hInstance);
		InitAcUiDLL();
	}
	else if (dwReason == DLL_PROCESS_DETACH) 
	{
		TtArxDLL.DetachInstance();

	}
	return TRUE;    // ok
}

extern "C" AcRx::AppRetCode 
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
	switch (msg) {
	case AcRx::kInitAppMsg:
		acrxDynamicLinker->unlockApplication(pkt);
		acrxDynamicLinker->registerAppMDIAware(pkt);
		InitApplication();
		break;
	case AcRx::kUnloadAppMsg:
		UnloadApplication();
		break;
	}
	return AcRx::kRetOK;
}

void InitApplication()
{
	void top_bar();
	void left_bar();
	void bottom_bar();
	AddCommand(_T("TG"), _T("TB"), _T("TB"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, top_bar);
	AddCommand(_T("TG"), _T("LB"), _T("LB"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, left_bar);
	AddCommand(_T("TG"), _T("BB"), _T("BB"), ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, bottom_bar);
}

void UnloadApplication()
{
	acedRegCmds->removeGroup(_T("TG"));
}

void AddCommand(const TCHAR* cmdGroup, const TCHAR* cmdInt, const TCHAR* cmdLoc,
				const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
{
	TCHAR cmdLocRes[65];

	if (idLocal != -1)
	{
		::LoadString(_hdllInstance, idLocal, cmdLocRes, 64);
		acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);

	}
	else
		acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
}
